package mspdt.pocket.wallet;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	DBAdapter db;
	private String password = null;
	private EditText password_field = null;
	private Button login_button = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		db = new DBAdapter(this);
		password_field = (EditText)findViewById(R.id.login_et_password);
		password = password_field.getText().toString();
		login_button = (Button)findViewById(R.id.login_button);
		login_button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				password = password_field.getText().toString();
				db.openDataBase();
				if(db.getPassword()==null)
				{
					//app anh ajillahad
					Bundle bundle = new Bundle();
					
					Intent create_password = new Intent(getApplicationContext(), CreateNewPassword.class);
					
					bundle.putBoolean("isHaveOld", false);
					
					create_password.putExtras(bundle);
					startActivity(create_password);
				}
				else if(db.getPassword().equals(password))
				{
					//password zov ue
					startActivity(new Intent(MainActivity.this, MainInformation.class));
				}
				else
				{
					//password buruu ue
					AlertDialog.Builder wrong_password_dialog = new AlertDialog.Builder(MainActivity.this);
					wrong_password_dialog.setTitle(getResources().getString(R.string.dialog_wrong_password_title));
					wrong_password_dialog.setMessage(getResources().getString(R.string.dialog_wrong_password_message));
//					wrong_password_dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
//						
//						@Override
//						public void onClick(DialogInterface dialog, int which) {
//							// TODO Auto-generated method stub
//							
//						}
//					});
					wrong_password_dialog.show();
				}
				db.close();
			}
		});
		
		
	}
}
